package com.gxr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.StrConvert;

import com.dao.ObjectDao;
import com.pro.bean.Users;

public class EditUserInfoServlet extends HttpServlet {

	/**
	 * �������û���Ϣ���浽��ݿ�
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 *
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		int userid=Integer.parseInt(request.getParameter("userid"));
		System.out.println("EditUserInfoServlet"+userid);
		
		String username=StrConvert.ToCN(request.getParameter("username"));
		String password=request.getParameter("password");
		String email=request.getParameter("email");
		String company=request.getParameter("company");
		
		
		HttpSession session=request.getSession();
		session.setAttribute("userid", userid);
		session.setAttribute("username", username);
		session.setAttribute("password", password);
		session.setAttribute("email", email);
		session.setAttribute("company", company);

		Users user=new Users();
		user.setUsername(username);
		user.setPassword(password);
		user.setEmail(email);
		user.setUserid(userid);
		//System.out.println(userid);
		user.setUnitid(Integer.parseInt(request.getParameter("company")));
		ObjectDao objectDao=new ObjectDao();
		try {
			objectDao.updates(user);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		RequestDispatcher dispatcher=request.getRequestDispatcher("SearchUserServlet");
		dispatcher.forward(request, response);
	
	}

}
